<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('departments', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('parent_id')->default(0)->comment('父部门ID');
            $table->string('name')->comment('部门名称');
            $table->string('code')->nullable()->comment('部门编码');
            $table->string('leader')->nullable()->comment('负责人');
            $table->string('phone')->nullable()->comment('联系电话');
            $table->string('email')->nullable()->comment('邮箱');
            $table->tinyInteger('status')->default(1)->comment('状态：1-启用，0-禁用');
            $table->integer('sort')->default(0)->comment('排序');
            $table->string('remark')->nullable()->comment('备注');
            $table->timestamps();
            $table->softDeletes();

            $table->index('parent_id');
            $table->index('status');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('departments');
    }
};

